//
//  BVMineDataaViewController.m
//  XiangYu
//
//  Created by YYKJ on 2017/6/7.
//  Copyright © 2017年 YYKJ. All rights reserved.
//  资料修改页面

#import "BVMineDataaViewController.h"
#import "BVPersonalDataViewController.h"
#import "BVChooseSpouseViewController.h"
#import "BVMineEditorViewController.h"

@interface BVMineDataaViewController ()<UIScrollViewDelegate>

@property (nonatomic ,strong) UIImageView      *headerView;
@property (nonatomic ,strong) NSArray          *textArray;

@property (nonatomic ,strong) UIView            *bgView;
@property (nonatomic ,strong) UIButton          *leftBtn;
@property (nonatomic ,strong) UIButton          *rightBtn;
@property (nonatomic ,strong) UIScrollView      *scrollView;
@property (nonatomic ,strong) NSArray           *controllerArray;

@end

@implementation BVMineDataaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor BVBackgroundLightGrayColor]];
    [self.navigationItem setTitle:@"个人资料"];
    
    [self setNav];
    [self layoutUI];
    [self addChildController];
}

-(void)setNav{
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setFrame:CGRectMake(0, 10, 40, 28)];
    [rightBtn setTitle:@"保存" forState:UIControlStateNormal];
    [rightBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [rightBtn.titleLabel setTextAlignment:NSTextAlignmentRight];
    [rightBtn addTarget:self action:@selector(setData) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    [self.navigationItem setRightBarButtonItem:rightBarBtn];
    
}

-(void)layoutUI{
    
    self.headerView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 150)];
    [self.view addSubview:self.headerView];
    [self.headerView setBackgroundColor:[UIColor clearColor]];
    [self.headerView setImage:[UIImage imageNamed:@"information_bac"]];
    [self.headerView setUserInteractionEnabled:YES];
    
    UIImageView *avatarImage = [[UIImageView alloc]initWithFrame:CGRectMake(40, 40, 70, 70)];
    [self.headerView addSubview:avatarImage];
    [avatarImage setImage:[UIImage imageNamed:@"icon-1mindd"]];
    [avatarImage.layer setMasksToBounds:YES];
    [avatarImage.layer setCornerRadius:35.0];
    
    self.bgView = [[UIView alloc]init];
    [self.view addSubview:self.bgView];
    [self.bgView setBackgroundColor:[UIColor whiteColor]];
    [self.bgView setFrame:CGRectMake(0, 150, ScreenW, 40)];
    
    self.leftBtn = [self segBtn];
    [self.bgView addSubview:self.leftBtn];
    [self.leftBtn setTitle:@"个人资料" forState:UIControlStateNormal];
    [self.leftBtn setTag:0];
    self.leftBtn.sd_layout
    .topSpaceToView(self.bgView, 0)
    .leftSpaceToView(self.bgView, 0)
    .widthIs(ScreenW/2)
    .heightIs(40);
    [self screeningBtnClick:self.leftBtn];
    
    UIView *view = [[UIView alloc]init];
    [self.bgView addSubview:view];
    [view setFrame:CGRectMake(self.bgView.width/2, 5, 1, 30)];
    [view setBackgroundColor:[UIColor BVLineGrayColor]];
    
    self.rightBtn = [self segBtn];
    [self.bgView addSubview:self.rightBtn];
    [self.rightBtn setTitle:@"择偶条件" forState:UIControlStateNormal];
    [self.rightBtn setTag:1];
    self.rightBtn.sd_layout
    .topSpaceToView(self.bgView, 0)
    .leftSpaceToView(view, 0)
    .widthIs(ScreenW/2)
    .heightIs(40);
    
}

-(void)setData{
    
     [[NSNotificationCenter defaultCenter]postNotification:[NSNotification notificationWithName:@"setSpouseConditions" object:nil userInfo:nil]];
}

-(void)addChildController{
    
    self.scrollView = [UIScrollView new];
    [self.view addSubview:self.scrollView];
    [self.scrollView setBackgroundColor:[UIColor blueColor]];
    [self.scrollView setShowsVerticalScrollIndicator:NO];
    [self.scrollView setShowsHorizontalScrollIndicator:NO];
    [self.scrollView setBounces:NO];
    [self.scrollView setContentSize:CGSizeMake(ScreenW*2, ScreenH-150-64-40)];
    [self.scrollView setUserInteractionEnabled:YES];
    [self.scrollView setDelegate:self];
    [self.scrollView setPagingEnabled:YES];
    [self.scrollView setScrollEnabled:NO];
    self.scrollView.sd_layout
    .topSpaceToView(self.bgView, 0)
    .leftSpaceToView(self.view, 0)
    .widthIs(ScreenW)
    .bottomSpaceToView(self.view,0);
    
    BVMineEditorViewController *minEditro = [[BVMineEditorViewController alloc]init];
    BVPersonalDataViewController *personData = [[BVPersonalDataViewController alloc]init];
    personData.monologueBlock = ^(NSString *str) {
        minEditro.navTitle = @"内心独白";
        minEditro.content = [str copy];
        ROOTNAVPUSH(minEditro, YES);
    };
    
    BVChooseSpouseViewController *chooseSpouse = [[BVChooseSpouseViewController alloc]init];
    self.controllerArray = @[personData,chooseSpouse];
    
    for (int i = 0; i < _controllerArray.count; i++) {
        UIView *viewcon = [[UIView alloc]
                           initWithFrame:CGRectMake(ScreenW*i, 0, ScreenW, ScreenH)];
        UIViewController *viewcontroller = self.controllerArray[i];
        viewcon = viewcontroller.view;
        
        [viewcon setFrame:CGRectMake(ScreenW*i, 0, ScreenW, ScreenH)];
        [self.scrollView addSubview:viewcon];
    }
    
}

-(void)screeningBtnClick:(UIButton *)btn{
    
    [self.leftBtn setTitleColor:[UIColor BVTextDarkGrayColor] forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:[UIColor BVTextDarkGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor BVBaseOrangeColor] forState:UIControlStateNormal];
    
    [self slidingScrollView:btn.tag];
}
#pragma mark - 获得滑动按钮的点击  移动scrllView的偏移量
- (void)slidingScrollView:(NSInteger )integer{
    
    [UIView animateWithDuration:0.1 animations:^{
        self.scrollView.contentOffset = CGPointMake(ScreenW*integer , 0);
    }];
    
}

#pragma mark - 将按钮封装起来
-(UIButton *)segBtn{
    
    UIButton *segBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [segBtn setTitleColor:[UIColor BVTextDarkGrayColor] forState:UIControlStateNormal];
    [segBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [segBtn addTarget:self action:@selector(screeningBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    return segBtn;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}


@end
